<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="courseSystem.bean.UserBean" %>
<%@ page import="courseSystem.bean.CourseBean" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%
    String prompt = (String) request.getSession().getAttribute("prompt");
    UserBean u = (UserBean) request.getSession().getAttribute("user");
    String keyWord = (String) request.getSession().getAttribute("keyWord");
    if (prompt != null) {
        out.println("<script>alert('" + prompt + "');</script>");
        request.getSession().removeAttribute("prompt");
    }
    String courseClass = (String) request.getSession().getAttribute("courseClass");
    List<CourseBean> courses = (List<CourseBean>) request.getSession().getAttribute(courseClass);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <%--    <base href="<%=basePath%>">--%>
    <title>管理员首页</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../css/myCss.css">
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <nav class="navbar navbar-default" role="navigation">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse"
                            data-target="#bs-example-navbar-collapse-1"><span
                            class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span
                            class="icon-bar"></span><span class="icon-bar"></span></button>
                    <a class="navbar-brand" href="../courseServlet?flag=all">全部课程</a>
                </div>
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li><a id="navbar-brand" href="#modal-container-1997" data-toggle="modal">添加课程</a></li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                <%=u.getUser().get("name")%>
                                <strong class="caret"></strong></a>
                            <ul class="dropdown-menu">
                                <li><a href="#modal-container-2024" data-toggle="modal">修改密码</a></li>
                                <li><a href="../doorServlet?flag=logout" data-toggle="modal">退出登录</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </nav>
            <div class="tab-content">
                <div class="tab-pane active" id="panel-771787">
                    <br/><br/>
                    <form action="../courseServlet?flag=find" method="post" class="navbar-form navbar-left"
                          role="search">
                        <div class="form-group">
                            <label for="keyWord">输入课程关键字：</label>
                            <input type="text" id="keyWord" name="keyWord" class="form-control"
                                   value="<%=(keyWord==null?"":keyWord)%>"/>
                        </div>
                        <button type="submit" class="btn btn-sm btn-info">查询</button>
                    </form>
                </div>
            </div>
            <div class="container">
                <div class="row clearfix">
                    <div class="col-md-12 column">
                        <%
                            if (!courses.isEmpty()) {
                                out.println("<table class=\"table table-bordered table-hover\">");
                                out.print("<thead><tr><th>编号</th><th>课程名</th><th>教师</th><th>教室</th><th>时间1-56（星期一五六节）" +
                                        "</th><th>学分</th><th>操作</th></tr></thead><tbody>");
                                for (int i = 0; i < courses.size(); i++) {
                                    HashMap<String, String> c = courses.get(i).getCourse();
                                    out.println("<tr class='" + (i % 2 == 0 ? "info" : "") + "'><td>"
                                            + c.get("course_id") + "</td><td>" + c.get("course_name")
                                            + "</td><td>" + c.get("teacher_name") + "</td><td>"
                                            + c.get("classroom") + "</td><td>" + c.get("course_time")
                                            + "</td><td>" + c.get("credits") + "</td>");%>
                        <td>
                            <a id="<%="modal-0921"+(i+2)%>" href="<%="#modal-container-0921"+(i+2)%>"
                               data-toggle="modal">修改</a>
                            <a id="<%="modal-19970921"+(i+2)%>" href="<%="#modal-container-19970921"+(i+2)%>"
                               data-toggle="modal">删除</a>
                        </td>
                        <%out.println("</tr>");%>
                        <div class="modal fade" id="<%="modal-container-0921"+(i+2) %>" role="dialog"
                             aria-labelledby="updateCourse" aria-hidden="true">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
                                        </button>
                                        <h3 class="modal-title" id="updateCourse">修改</h3>
                                    </div>
                                    <div class="modal-footer">
                                        <form action="<%="../courseServlet?flag=update&course_id="+c.get("course_id")%>"
                                              method="post">
                                            <div class="form-group">
                                                <div class="col-xs-12  ">
                                                    <div class="input-group">
                                                    <span class="input-group-addon"><span
                                                            class="glyphicon" style="width: 30px">课程名</span></span>
                                                        <label for="course_name"></label>
                                                        <input type="text" id="course_name" name="course_name"
                                                               class="form-control"
                                                               value="<%=c.get("course_name") %>"/>
                                                    </div>
                                                    <div class="input-group">
                                                    <span class="input-group-addon"><span
                                                            class="glyphicon" style="width: 30px">教师名</span></span>
                                                        <label for="teacher_name"></label>
                                                        <input type="text" id="teacher_name" name="teacher_name"
                                                               class="form-control"
                                                               value="<%=c.get("teacher_name") %>"/>
                                                    </div>
                                                    <div class="input-group">
                                                    <span class="input-group-addon"><span
                                                            class="glyphicon" style="width: 30px">教室</span></span>
                                                        <label for="classroom"></label>
                                                        <input type="text" id="classroom" name="classroom"
                                                               class="form-control"
                                                               value="<%=c.get("classroom") %>"/>
                                                    </div>
                                                    <div class="input-group">
                                                    <span class="input-group-addon"><span
                                                            class="glyphicon" style="width: 30px">时间</span></span>
                                                        <label for="course_time"></label>
                                                        <input type="text" id="course_time" name="course_time"
                                                               class="form-control"
                                                               value="<%=c.get("course_time") %>"/>
                                                    </div>
                                                    <div class="input-group">
                                                    <span class="input-group-addon"><span
                                                            class="glyphicon" style="width: 30px">学分</span></span>
                                                        <label for="credits"></label>
                                                        <input type="text" id="credits" name="credits"
                                                               class="form-control"
                                                               value="<%=c.get("credits") %>"/>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group form-actions">
                                                <div class="col-xs-4 col-xs-offset-4 ">
                                                    <button type="button" class="btn btn-default" data-dismiss="modal">
                                                        <span class="glyphicon">关闭</span>
                                                    </button>
                                                    <button type="submit" class="btn btn-primary">
                                                        <span class="glyphicon">保存</span>
                                                    </button>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal fade" id="<%="modal-container-19970921"+(i+2) %>" role="dialog"
                             aria-labelledby="deleteCourse" aria-hidden="true">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
                                        </button>
                                        <h3 class="modal-title" id="deleteCourse">删除！</h3>
                                    </div>
                                    <form action="<%="../courseServlet?flag=delete&course_id="+c.get("course_id")%>"
                                          method="post">
                                        <h3>确定删除该条记录？</h3>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                                            </button>
                                            <button type="submit" class="btn btn-primary">确定</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <% }
                            out.println("</tbody></table>");
                        } else out.println("<div class=\"alert alert-danger\">未查询到课程名中包含“" + keyWord + "”的课程</div>");
                        %>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="modal-container-1997" role="dialog" aria-labelledby="addCourse" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 class="modal-title" id="addCourse">添加内容</h3>
            </div>
            <div class="modal-footer">
                <form action="../courseServlet?flag=add" method="post">
                    <div class="form-group">
                        <div class="col-xs-12  ">
                            <div class="input-group">
                            <span class="input-group-addon">
                                <span class="glyphicon" style="width: 30px">课程名</span></span>
                                <label for="cn"></label>
                                <input type="text" id="cn" name="course_name" class="form-control"/>
                            </div>
                            <div class="input-group">
                            <span class="input-group-addon">
                                <span class="glyphicon" style="width: 30px">教师</span></span>
                                <label for="tn"></label>
                                <input type="text" id="tn" name="teacher_name" class="form-control"/>
                            </div>
                            <div class="input-group">
                            <span class="input-group-addon">
                                <span class="glyphicon" style="width: 30px">教室</span></span>
                                <label for="cr"></label>
                                <input type="text" id="cr" name="classroom" class="form-control" placeholder="##栋###"/>
                            </div>
                            <div class="input-group">
                            <span class="input-group-addon">
                                <span class="glyphicon" style="width: 30px">时间</span></span>
                                <label for="ct"></label>
                                <input type="text" id="ct" name="course_time" class="form-control" placeholder="##-##周-星期#-第##节"/>
                            </div>
                            <div class="input-group">
                            <span class="input-group-addon">
                                <span class="glyphicon" style="width: 30px">学分</span></span>
                                <label for="cd"></label>
                                <input type="text" id="cd" name="credits" class="form-control"/>
                            </div>
                        </div>
                    </div>
                    <div class="form-group form-actions">
                        <div class="col-xs-4 col-xs-offset-4 ">
                            <button type="button" class="btn btn-default" data-dismiss="modal">
                                <span class="glyphicon">关闭</span>
                            </button>
                            <button type="submit" class="btn btn-primary">
                                <span class="glyphicon">保存</span>
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="modal-container-2024" role="dialog" aria-labelledby="changePass" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
                <h3 class="modal-title" id="changePass">修改密码</h3>
            </div>
            <div class="modal-footer">
                <form action="../doorServlet?flag=change" method="post">
                    <div class="form-group">
                        <div class="col-xs-12  ">
                            <div class="input-group">
                                <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
                                <label for="pass1"></label>
                                <input id="pass1" type="text" name="pass1" class="form-control" placeholder="旧密码"/>
                            </div>
                            <div class="input-group">
                                <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
                                <label for="pass2"></label>
                                <input id="pass2" type="password" name="pass2" class="form-control"
                                       placeholder="新密码"/>
                            </div>
                            <div class="input-group">
                                <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
                                <label for="pass3"></label>
                                <input id="pass3" type="password" name="pass3" class="form-control"
                                       placeholder="确认密码"/>
                            </div>
                        </div>
                        <input type="hidden" name="userClass" value="admin">
                    </div>
                    <div class="form-group form-actions">
                        <div class="col-xs-4 col-xs-offset-4 ">
                            <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-ok"></span>提交
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
</html>
